package com.gadgets.framework.controller;

import com.gadgets.framework.start.AbsCacheInitLoaderProcess;
import com.gadgets.framework.start.AbstractInitLoaderProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * @author UncleXiu
 * @version V1.0.0
 * @data 2022-02-10
 */
@Component
public class CacheRefreshInitLoad extends AbstractInitLoaderProcess {

    @Autowired
    private CacheRefreshController cacheRefreshController;

    public CacheRefreshInitLoad() {
        super(Integer.MIN_VALUE+1);
    }

    /**
     * 初始化执行方法
     *
     * @param context Spring上下文
     */
    @Override
    public void initLoad(ApplicationContext context) {
        String[] beanNamesForType = context.getBeanNamesForType(AbsCacheInitLoaderProcess.class);
        if(beanNamesForType.length>0){
            for (String cacheInitBeanName : beanNamesForType) {
                logger.info("注册缓存加载器：{}",cacheInitBeanName);
                cacheRefreshController.addProcessList(context.getBean(cacheInitBeanName, AbsCacheInitLoaderProcess.class));
            }
        }
    }

}
